/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package vn.hva.bluepumpkin.util;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 *
 * @author Leung
 */
public class ValidatorUtils {

    public static boolean compareDates(Date date, Date d2) {
        DateFormat df = new SimpleDateFormat("MM-dd-yyyy");
        if (date.before(d2)) {
            return true;
        } else {
            return false;
        }
    }


    public static boolean checkDate(String inDate, String dateFormat) {

        int dateFormatLength = dateFormat.length();

        try {

            if (inDate.length() != dateFormatLength) {
                throw new Exception();
            } else {

                SimpleDateFormat format = new SimpleDateFormat(dateFormat);

                format.setLenient(false);

                Date theDate = new Date();

                theDate = format.parse(inDate);

                return true;

            }

        } catch (Exception e) {

            return false;

        }

    }

    public static boolean checkDate(String inDate) {

        String dateFormat = "MM/dd/yyyy";

        int dateFormatLength = dateFormat.length();

        try {

            if (inDate.length() != dateFormatLength) {
                throw new Exception();
            } else {

                SimpleDateFormat format = new SimpleDateFormat(dateFormat);

                format.setLenient(false);

                Date theDate = new Date();

                theDate = format.parse(inDate);

                return true;

            }

        } catch (Exception e) {

            return false;

        }

    }

    public static boolean tryParseInteger(String number) {
        try {
            Integer.parseInt(number);
            return true;
        } catch (NumberFormatException ex) {
            return false;
        }
    }

}
